<%@ page import="com.example.ordersystem.domain.Order" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: 檬zhu
  Date: 2021/12/14
  Time: 23:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
    <title></title>
</head>
<jsp:include page="title.jsp"/>
<%
    Object object = request.getAttribute("orders");//获取当前顾客的所有订单项
    List<Order> orders = null;

    /*订单项是否为空*/
    int status = 0;

    if (object == null) {
        status = -1;
    } else {
        orders = (List<Order>) object;
        if (orders.size() == 0)
            status = -1;
    }

    if (status == -1) {
%>
<jsp:include page="/customer/nothing"/>
<%
        return;    //不再执行接下来的代码
    }
%>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>查看历史订单</legend>
</fieldset>
<ul class="layui-timeline" style="margin-left: 15%">
    <%
        for (Order order : orders) {
            String orderStatus = order.getStatus();
    %>

    <li class="layui-timeline-item">
        <i class="layui-icon layui-timeline-axis"></i>
        <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title"><%=order.getBirth()%></h3>
                订单金额：<button type="button" class="layui-btn layui-btn-primary" style="width: 90px"><%=order.getTotal()%>元</button>
            <br>订单状态：<button type="button" class="layui-btn layui-btn-normal" style="width: 90px"><%=orderStatus%></button>
                <%
                    /*支付成功状态*/
                    if (orderStatus.equals(Order.TRADE_STATUS.get(Order.SUCCESS))) {
                %>
                <form style="margin-top: 4px" action="${pageContext.request.contextPath}/customer/applyRefund" method="post" onsubmit="return window.confirm('确认申请退款？')">
                    <input type="hidden" name="orderNum" value="<%=order.getNum()%>">
                    <input type="submit" value="申请退款" class="layui-btn layui-btn-danger" style="width: 90px">
                </form>

                <form style="margin-top: 4px" action="${pageContext.request.contextPath}/customer/confirmTrade" method="post" onsubmit="return window.confirm('确认收货么？')">
                    <input type="hidden" name="orderNum" value="<%=order.getNum()%>">
                    <input type="submit" value="确认收货" class="layui-btn layui-btn-warm" style="width: 90px">
                </form>
                <%
                    }
                %>
                <%
                    /*待付款状态*/
                    if (orderStatus.equals(Order.TRADE_STATUS.get(Order.WAIT_BUYER_PAY))) {
                %>
                <form action="${pageContext.request.contextPath}/customer/payOrder" target="_blank">
                    <input type="hidden" name="orderNum" value="<%=order.getNum()%>">
                    <input type="hidden" name="amount" value="<%=order.getTotal()%>">
                    <input type="submit" value="付款" class="layui-btn layui-btn-warm">
                </form>
                <form style="margin-top: 4px" action="${pageContext.request.contextPath}/customer/cancelTrade" method="post" onsubmit="return window.confirm('确认取消订单？')">
                    <input type="hidden" name="orderNum" value="<%=order.getNum()%>">
                    <input type="hidden" name="amount" value="<%=order.getTotal()%>">
                    <input type="submit" value="取消订单" class="layui-btn layui-btn-danger" style="width: 90px">
                </form>
                <%
                    }
                %>
                <br><a href="${pageContext.request.contextPath}/customer/orderDetail?orderNum=<%=order.getNum()%>">查看详情</a>
        </div>
    </li>
    <%
        }
    %>
</ul>
</body>
</html>
